﻿using System.Collections.Generic;
using AmazeUI.bll.Open.Weixin;
using AmazeUI.bll.Open.WeixinPay;
using AmazeUI.Imodel;
using Newtonsoft.Json;

namespace AmazeUI.bll.Open.OpenModel
{
    [JsonObject(MemberSerialization.OptOut)]
    public class WxPayConfig  
    {
        private WxConfig Wc;

        public WxPayConfig(WxConfig wc,  string packageId)
            : base()
        {

            this.package = "prepay_id=" + packageId;
            Wc = wc;
            this.signType = "MD5";


            Sign();
        }

           void Sign()
        {
            //var data = string.Format("appId={0}&nonceStr={1}&package={2}&signType={3}&timeStamp={4}&key={5}", this.appId, this.nonceStr, this.package, "MD5", this.timestamp, WxPackage.Key);
            //this.paySign = WebCommon.Encryption.Md532(data).ToUpper();

            var sd = new SortedDictionary<string, string>();
            sd.Add("appId", Wc.appId);
            sd.Add("timeStamp", Wc.timestamp);
            sd.Add("nonceStr", Wc.nonceStr);
            sd.Add("package",   package);
            sd.Add("signType", this.signType);
            var ob = WebCommon.StringCommand.Static.GetOrderBy(sd);
            this.paySign = WxCommon.GetStringSignTemp(ob, WxPackage.Key);
        }
        /// <summary>
        /// appId
        /// </summary>
        [JsonProperty]
        public string appId { get { return Wc.appId; } }
        /// <summary>
        /// timeStamp
        /// </summary>
        [JsonProperty]
        public string timeStamp { get { return Wc.timestamp; } }
        /// <summary>
        /// nonceStr
        /// </summary>
        [JsonProperty]
        public string nonceStr { get { return Wc.nonceStr; } }
        /// <summary>
        /// packageid
        /// </summary>
        [JsonProperty]
        public string package { get; private set; }
        /// <summary>
        /// 
        /// </summary>
             [JsonProperty]
        public string signType { get; private set; }//微信签名方式：
        /// <summary>
        /// 支付前面
        /// </summary>
             [JsonProperty]
        public string paySign { get; private set; }//微信签名 

        /// <summary>
        /// 功能
        /// </summary>
             [JsonProperty]
        public string[] jsApiList
        {
            get
            {
                return new[]
            {
                "checkJsApi", "onMenuShareTimeline", "showAllNonBaseMenuItem", "chooseImage", "uploadImage",
                "previewImage", "downloadImage", "onMenuShareTimeline", "onMenuShareAppMessage",
                "onMenuShareQQ", "onMenuShareQZone", "onMenuShareWeibo","chooseWXPay",
            };
            }

        }//功能 

       
    }
}